package com.work.music.controller;

import com.work.music.common.ResponseJson;
import com.work.music.exception.AjaxOperationFailException;
import com.work.music.service.AdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

@Controller
public class AdminController extends BaseController {
    @Autowired
    private AdminService adminService;

    /**
     * 登录
     * @return
     * @throws AjaxOperationFailException
     */
    @RequestMapping("/admin/login.json")
    @ResponseBody
    public ResponseJson login() throws AjaxOperationFailException {
        return adminService.login();
    }

    /**
     * 退出登录
     * @return
     * @throws AjaxOperationFailException
     */
    @RequestMapping("/acp/loginOut.json")
    @ResponseBody
    public ResponseJson loginOut(){
        adminService.loginOut();
        return new ResponseJson();
    }

    /**
     * 修改密码
     * @return
     * @throws AjaxOperationFailException
     */
    @RequestMapping("/acp/changePwd.json")
    @ResponseBody
    public ResponseJson changePwd() throws AjaxOperationFailException {
        return adminService.changePwd();
    }


    @RequestMapping("acp/admin/list.html")
    public String adminListHtml() {
        return "view/admin/list";
    }
    /**
     * 获取列表信息
     * @return
     * @throws AjaxOperationFailException
     */
    @RequestMapping("/acp/adminList.json")
    @ResponseBody
    public ResponseJson adminList() {
        return adminService.adminList();
    }

    @RequestMapping("/acp/admin/edit.html")
    public ModelAndView editHtml() {
        ModelAndView modelAndView = new ModelAndView("view/admin/edit");
        modelAndView.addObject("admin", adminService.selectAdminInfoById());
        return modelAndView;
    }

    @RequestMapping("/acp/admin/edit.json")
    @ResponseBody
    public ResponseJson editJson() throws AjaxOperationFailException {
        return adminService.editJson();
    }

    @RequestMapping("/acp/admin/del.json")
    @ResponseBody
    public ResponseJson delJson() throws AjaxOperationFailException {
        return adminService.delJson();
    }

    @RequestMapping("/acp/admin/loglist.html")
    public String adminLogListHtml() {
        return "view/admin/logList";
    }

    @RequestMapping("/acp/adminLogList.json")
    @ResponseBody
    public ResponseJson adminLogList() {
        return adminService.adminLogList();
    }
}
